Skip to content

Make every opt-out fail closed (0.5.0) - #46

Merged
dmccoystephenson merged 1 commit into
mainfrom
fix/opt-out-fails-closed
Nov 19, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
fix/opt-out-fails-closed

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Every opt-out now fails closed: a switch that does not clearly mean "on" turns usage reporting off, so a disabled setting can never be read as consent. This is the JavaScript counterpart of Stephenson-Software/trace-client-java#51 (0.8.0).

Since 0.2.0 the client reads the environment itself (0.1.0 left that to the consumer); this brings that reading, and the enabled option, to the Java semantics.

Fail-open paths fixed

  • TRACE_USAGE_REPORTING only turned reporting off for off/false/0/no. Now anything but blank or true/on/yes/1 turns it off.
  • DO_NOT_TRACK only turned reporting off for 1/true/yes. Now anything but blank or 0/false/off/no turns it off.
  • environmentOptsOut() caught an unreadable environment and returned false, and processEnvironment() swallowed a throwing process.env as an empty one. Both now count as opting out. A non-string env value (untyped code) opts out too. A runtime with no process / no process.env still opts nothing out.
  • The constructor only disabled on enabled === false, so enabled: "false", null, undefined or 0 from a config file or untyped code reported. When given, enabled is now read through allowsReporting(); left out, it still defaults to on.
  • The README examples (and the doc-comment example) used process.env.USAGE_REPORTING_ENABLED !== "false", which reads off, FALSE or a typo as on. They now use TraceClient.allowsReporting(process.env.USAGE_REPORTING_ENABLED ?? true); the CHANGELOG tells consumers who copied the old line to switch.

New helper

TraceClient.allowsReporting(value), a static member like the other post-0.1.0 additions, so the module's exported values are unchanged. True only for true or a string true/on/yes/1 (any case, trimmed).

The client reads no config-file switch of its own (the install-ID file holds only an ID), so the file rules do not apply.

Version

0.4.1 → 0.5.0 in package.json, package-lock.json, the header comment, TRACE_CLIENT_VERSION and the README User-Agent line. CHANGELOG entry under [Unreleased].

Tests

npm test: 90 tests, 90 pass. npm run typecheck: clean. Tests pinning the fail-open behaviour (non-string values and throwing environments opting nothing out, disabled leaving reporting on) were updated; new tests cover unfamiliar values for both variables, allowsReporting, and the enabled option.

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

A switch that does not clearly mean "on" now turns reporting off, so an
opt-out can never be read as consent (trace-client-java 0.8.0 counterpart):

- TRACE_USAGE_REPORTING set to anything but blank or true/on/yes/1 now
  disables; only off/false/0/no did.
- DO_NOT_TRACK set to anything but blank or 0/false/off/no now disables;
  only 1/true/yes did.
- An environment that cannot be read (process.env or an env lookup
  throwing) now disables; it used to opt nothing out. A non-string env
  value disables too. No process / no process.env still opts nothing out.
- The enabled option, when given, is read through the new
  TraceClient.allowsReporting(); only enabled: false turned it off, so
  "false", null, undefined or 0 reported. Left out, it defaults to on.
- README examples use allowsReporting(process.env.USAGE_REPORTING_ENABLED
  ?? true) instead of !== "false", which read "off" or a typo as on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant